//
//  LTY_ClassTableViewCell.m
//  MooMusic
//
//  Created by 守护神 on 15/10/22.
//  Copyright © 2015年 wjy. All rights reserved.
//

#import "LTY_ClassTableViewCell.h"
// 导入classCollectionView的自定义cell头文件
#import "LTY_ClassCollectionViewCell.h"

static NSString *const cellCollection = @"cellCollection";

@implementation LTY_ClassTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatSubClassViews];
    }
    return  self;
}

// 创建视图
- (void)creatSubClassViews
{
    [self creatClassUICollectionView];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    if (self.subArray.count > 0) {
        // 刷新collectionview
        [ClassCollectionView reloadData];
    }
}

// 创建collectionview
- (void)creatClassUICollectionView
{
#pragma mark -- UICollectionView
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    // item大小 (宽  高)
    flowLayout.itemSize = CGSizeMake(SCREENWIDTH / 5.5, 50);
    // 最小的行间距 (垂直于滚动方向的是一行)
    flowLayout.minimumLineSpacing = 1;
    // 最小的列间距  cell的大小 section的缩进 共同来决定的item之间的距离
    flowLayout.minimumInteritemSpacing = 1;
    // 滚动方向 (纵向滚动)
    flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    // section的缩进 (上 左 下 右)
    flowLayout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
    
    
    ClassCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 130) collectionViewLayout:flowLayout];
    
    ClassCollectionView.backgroundColor =[UIColor whiteColor];
    
    ClassCollectionView.delegate = self;
    ClassCollectionView.dataSource = self;
    
    // 取消滑动
    ClassCollectionView.bounces = NO;
    
    // 注册item样式
    [ClassCollectionView registerClass:[LTY_ClassCollectionViewCell class] forCellWithReuseIdentifier:cellCollection];
    
    // 添加到父视图上
    [self.contentView addSubview:ClassCollectionView];
    
    
}

#pragma mark -- UICollectionViewDataSource
// 每个section中的item的个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return [self.TypeArr1 count];
}

// item重用池
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    LTY_ClassCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellCollection forIndexPath:indexPath];
    
    cell.backgroundColor = [UIColor lightGrayColor];
    
    cell.label.text = [[self.TypeArr1 objectAtIndex:indexPath.item] valueForKey:@"name"];
    
    return cell;
    
}

// collectionView点击事件
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    NSLog(@"+_+_+_+_+  %@", [[self.TypeArr1 objectAtIndex:indexPath.item] valueForKey:@"order"]);
    
    // 触发方法 调用Block
    self.LBsendBlock([[self.TypeArr1 objectAtIndex:indexPath.item] valueForKey:@"name"], [[self.TypeArr1 objectAtIndex:indexPath.item] valueForKey:@"order"], [[self.TypeArr1 objectAtIndex:indexPath.item] valueForKey:@"id"]);
    
    
}






- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
